package com.len.service.impl;

import com.len.base.BaseMapper;
import com.len.base.impl.BaseServiceImpl;
import com.len.entity.BehaviorField;
import com.len.mapper.BehaviorFieldMapper;
import com.len.service.BehaviorFieldService;
import com.len.util.ReType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author songxiangyang
 * @date 2019/03/15.
 */
@Service
public class BehaviorFieldServiceImpl extends BaseServiceImpl<BehaviorField,String> implements BehaviorFieldService {

  @Autowired
  private BehaviorFieldMapper behaviorFieldMapper;

  @Override
  public BaseMapper<BehaviorField, String> getMappser() {
    return behaviorFieldMapper;
  }

  @Override
  public int deleteByPrimaryKey(String id) {
    return behaviorFieldMapper.deleteByPrimaryKey(id);
  }

  @Override
  public int insert(BehaviorField record) {
    record=super.addValue(record,true);
    return behaviorFieldMapper.insert(record);
  }
  
  @Override
  public BehaviorField selectByPrimaryKey(String id) {
    return behaviorFieldMapper.selectByPrimaryKey(id);
  }

  @Override
  public int updateByPrimaryKeySelective(BehaviorField record) {
    return behaviorFieldMapper.updateByPrimaryKeySelective(record);
  }

  @Override
  public int updateByPrimaryKey(BehaviorField record) {
    return behaviorFieldMapper.updateByPrimaryKey(record);
  }

  @Override
  public List<BehaviorField> selectListByPage(BehaviorField behavior) {
    return behaviorFieldMapper.selectListByPage(behavior);
  }

  @Override
  public ReType loadsBehaviorFieldByFlag(BehaviorField behaviorField) {
    ReType reType = new ReType();
    List<Map<String, String>> data = new ArrayList<>();
    Map<String, String> map = new HashMap();
    List<BehaviorField> behaviorFields = behaviorFieldMapper.select(behaviorField);
    behaviorFields.forEach(df ->{
      String id = df.getId();
      String fieldName = df.getFieldName();
      map.put(id, fieldName);
    });
    data.add(map);
    reType.setData(data);
    return reType;
  }

  @Override
  public int selectCountByCondition(BehaviorField behaviorField) {
    return behaviorFieldMapper.selectCountByCondition(behaviorField);
  }
}
